package com.homelock.common.vo;

import com.alibaba.druid.util.StringUtils;
import com.homelock.common.constants.Constants;

import java.io.Serializable;

/**
 * Created by shixj on 2017/7/21.
 */
public class Resp implements Serializable {
	private int status;// 状态码
	private String msg;// 状态信息
	private Object data;// 数据对象
	
	public Resp() {
	}

	public Resp(int statusCode, String msg, Object data) {
		this.status = statusCode;
		this.msg = msg;
		this.data = data;
	}

	public Resp(int statusCode, Object data) {
		this.status = statusCode;
		this.data = data;
		this.msg = "";
	}

	public static Resp ok() {
		return new Resp(Constants.REQUEST_STATUS_SUCCESS, "成功");
	}

	public static Resp ok(String msg) {
		return new Resp(Constants.REQUEST_STATUS_SUCCESS, msg);
	}
	
	public static Resp ok(Object data) {
		return new Resp(Constants.REQUEST_STATUS_SUCCESS, "成功", data);
	}

	public static Resp ok(String msg, Object data) {
		if (StringUtils.isEmpty(msg)) {
			msg = "成功";
		}
		return new Resp(Constants.REQUEST_STATUS_SUCCESS, msg, data);
	}

	public static Resp faild() {
		return new Resp(Constants.REQUEST_STATUS_FAILD, "失败");
	}

	public static Resp faild(String msg) {
		return new Resp(Constants.REQUEST_STATUS_FAILD, msg);
	}

	public static Resp faild(String msg, Object data) {
		if (StringUtils.isEmpty(msg)) {
			msg = "失败";
		}
		return new Resp(Constants.REQUEST_STATUS_FAILD, msg, data);
	}

	public static Resp error() {
		return new Resp(Constants.REQUEST_STATUS_ERROR, "异常");
	}

	public static Resp error(String msg) {
		return new Resp(Constants.REQUEST_STATUS_ERROR, msg);
	}

	public static Resp error(String msg, Object data) {
		if (StringUtils.isEmpty(msg)) {
			msg = "异常";
		}
		return new Resp(Constants.REQUEST_STATUS_ERROR, msg, data);
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

}
